<!DOCTYPE html>
<!--
 Copyright (c) 2014-2019 fortiss GmbH
 			   2019 Johannes Kepler University Linz
 			   2019 Andrea Zoitl
  
 This program and the accompanying materials are made available under the
 terms of the Eclipse Public License 2.0 which is available at
 http://www.eclipse.org/legal/epl-2.0.

 SPDX-License-Identifier: EPL-2.0
 
 Contributors:
   Waldemar Eisenmenger, Jose Cabral, Milan Vathoopan
     - initial API and implementation and/or initial documentation
   Bianca Wiesmayr
   	- adapting, restructuring and extending the installation tutorial
   Andrea Zoitl
    - fixed 4diac branding, corrected links, improved readability
   
-->

<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <title>Building 4diac&nbsp;FORTE on Raspberry Pi</title>
      <link rel="stylesheet" type="text/css" href="../help.css">
   </head>

  <body>

<!--********************************************************************************************-->

     <h1 id="topOfPage">Introduction</h1>
      <p>This guide is for compiling&nbsp;FORTE for the Raspberry Pi. 
      For information about the parameters to be used, go to <a href="../../html/parameters/parameters.html#sysfs">Parameters</a>.</p>

      <p><a href="https://www.raspberrypi.org/" target="_blank">Raspberry Pi</a> (RPI) is one of the most famous low-cost embedded systems. 
      In its third generation, the Raspberry Pi 3 was launched in February 2016. 
      It has a 1.2GHz 64-bit quad-core ARMv8 CPU, 1 GB RAM and several I/O options, among them a 40 pin header. 
      The operating system is loaded from a SD card, so it can support many OS.
      The most popular one is the Debian-based Raspbian. 
      4diac&nbsp;FORTE previously used the <span class="specificText">wiringPi</span> library, but it has changed to use the sysFs virtual file system.</p>
    
      <p>This tutorial explains first how to compile 4diac&nbsp;FORTE in the RPI, or even cross-compile, and how to easily use the I/O Function Blocks in 4diac&nbsp;FORTE to control the 40 pin
      header.</p>

<!--***************-->
     
      <h2>Getting the RPI ready</h2>
       
      <p>This tutorial doesn't show the details of how to make the RPI run, but if you never used before, you should know that beside the RPI board, you need a source power that is
      connected to the mini-USB port and a mini-SD card. 
      The RPI can be connected to a screen, mouse and keyboard through the HDMI and USB ports, but you also can connect to it headless,
      meaning that you connect through ssh using the Ethernet or a usb-wifi connector. 
      There are plenty of tutorials on how to access the RPI, so this tutorial assumes that you have access
      to the command line of the RPI, through ssh or directly on it using the GUI, and that the RPI has Internet access.</p>

<!--********************************************************************************************-->
   
    <h1 id="onRPI">Building 4diac&nbsp;FORTE on the RPI</h1>

<!--***************-->
      
      <h2 id="preparation">Preparation</h2>
        <ol>
          <li>Install the additional software needed on your RPI. 
            <ul>
              <li>Git: 4diac&nbsp;FORTE is stored as a Git repository on the Eclipse server.</li>
              <li>The building tools: cmake, make, gcc, g++</li>
            </ul>
            <div class="code">$ sudo apt-get install git cmake make gcc g++</div>
          </li>
        </ol> 

<!--***************-->
          
      <h2 id="building">Building</h2> 
        <ol>
          <li>Check out 4diac&nbsp;FORTE from the Git repository in your home directory.
            <div class="code">$ cd ~
$ git clone https://git.eclipse.org/r/4diac/org.eclipse.4diac.forte</div>
          </li>
          <li>Prepare the 4diac&nbsp;FORTE project structure for the Posix architecture.
				    <div class="code">$ cd org.eclipse.4diac.forte
$ chmod +x setup_posix.sh</div>
              <p>You will need to add the SysFs module to the compilation. In order to that, you will need to change the <span class="fileLocation">setup_posix.sh</span> file, using your preferred text editor.
              In the file you will find a line that starts with <span class="specificText">cmake -G "Unix Makefiles" -DFORTE_ARCHITECTURE=Posix</span>. At the end of the line, add
              <span class="specificText"> -DFORTE_MODULE_SysFs=ON</span>. 
              This will enable the interface to the 40 pin header of the RPI. 
              Save the file, exit the editor and execute:</p>
               <div class="code">$ ./setup_posix.sh</div>
               <p>When no error occurs, the command creates a folder in bin/posix where all the files to compile 4diac&nbsp;FORTE are stored. 
               Access the folder if not already there.</p>
           </li>
				<li>Execute "make", which will start the compilation.
            <div class="code">$ make</div>
          </li>
      </ol>

<!--********************************************************************************************-->
      
    <h1 id="crossCompiling">Cross-compiling for the RPI</h1>
    
	    <p>The RPI is a very powerful computer, but when developing a project, one sometimes has to compile 4diac&nbsp;FORTE many times.
	    As the RPI is slow compared to the power of a desktop computer, cross-compiling is useful. 
	    It allows to compile on your desktop machine, and then send the executable to the RPI.</p>
	    
	    <p>You will need the 4diac&nbsp;FORTE source code, and the same additional tools used in the preparation, except CMake because CMake-GUI will be needed in this case.</p>

<!--***************-->
	    
      <h2 id="crossCompilingLinux">Cross-compiling using Linux</h2>
        <ol>
          <li>Install needed additional tools:
            <ul>
              <li>CMake-GUI
                <div class="code">$ sudo apt-get install cmake-qt-gui</div>
              </li>
              <li>Linaro Cross-compiling Toolchain. You can download it from <a href="https://releases.linaro.org/archive/15.06/components/toolchain/binaries/4.8/arm-linux-gnueabihf/gcc-linaro-4.8-2015.06-x86_64_arm-linux-gnueabihf.tar.xz" target="_blank">this</a> link.
                Then, you should de-compress this file
                <div class="code">$ tar -xvf gcc-linaro-4.8-2015.06-x86_64_arm-linux-gnueabihf.tar.xz</div>
                You could avoid downloading and de-compressing the file using the command
                <div class="code">$ sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf</div>
                but this method gave some errors in some cases. 
              </li>
            </ul>
          <li>Open CMake-GUI and complete as shown in the image
            <ol>
              <li>Set the 4diac&nbsp;FORTE source path where you cloned the Git repository.</li>
              <li>Set path for binaries where you want to create the executable. 
              Normally, <span class="folderLocation">bin/raspPi is used.</span></li>
              <li>Press <span class="button4diac">Configure</span></li>
            </ol>
            <p><img src="../../html/installation/img/raspiCrossLinux1.png" alt="Selecting folders in CMake"/></p>
          </li>
           <li>CMake Setup
            <ol>
              <li>Select the tool you normally use to compile your programs. 
              This example follows using UNIX Makefiles from the list.</li>
              <li>Select <span class="button4diac">Specify tools for cross-compiling</span></li>
              <li>Press <span class="button4diac">Next</span></li>
            </ol>
            <p><img src="../../html/installation/img/raspiCrossLinux2.png" alt="CMake Setup"/></p>
          </li>
          <li>CMake Setup
            <ol>
              <li>Write a name for the OS (normally Raspbian, it won't affect the compilation).</li>
              <li>Select the path to the C cross-compiler called arm-linux-gnueabihf-gcc, in the bin folder of the downloaded tools' folder. 
              If not found, you could execute:
                <div class="code">$ which arm-linux-gnueabi-gcc</div> 
              </li>
              <li>Select the path to the C++ cross-compiler called arm-linux-gnueabihf-g++, in the bin folder of the downloaded tools' folder. 
              If not found, you could execute:
                <div class="code">$ which arm-linux-gnueabi-g++</div> 
              </li>
              <li>The target root field can be left empty.</li>
              <li>Click <span class="button4diac">Finish</span></li>
            </ol>
            <p><img src="../../html/installation/img/raspiCrossLinux3.png" alt="Select cross-compiling tools."/></p>
          </li>
          <li>Configure the compilation
             <p>A list with all variables of 4diac&nbsp;FORTE in red should be shown in CMake as the picture below.</p>
            <ol>
              <li>Choose your Eclipse version if you selected it in step 3.1. Otherwise, it can be left as it is.</li>
              <li>Set the FORTE_ARCHITECTURE variable to Posix</li>
              <li>Enable FORTE_MODULE_SysFs and all other modules that you want</li>
              <li>Click <span class="button4diac">Configure</span> and the variables that need revision will appear again in red and the rest in white. 
              Check these variables and press <span class="button4diac">Configure</span> until no variable is shown in red.</li>
            </ol>
            <p><img src="../../html/installation/img/raspiCrossLinux4.png" alt="Configure 4diac FORTE compilation."/></p>
          </li>
          <li>Generate files
            <ul>
              <li>Click <span class="button4diac">Generate</span></li>
            </ul>
            <p><img src="../../html/installation/img/raspiCrossLinux5.png" alt="Generate the makefiles."/></p>
          </li>
          <li>Build 4diac&nbsp;FORTE
            <ul>
              <li>Go to the recently generated folder and execute make (or build it as you normally do)
               <div class="code">$ cd bin/raspPi
$ make</div> 
              </li>
            </ul>
          </li>
        </ol>

<!--***************-->
        
      <h2 id="crossCompilingWindows">Cross-compiling using Windows</h2>
        <ol>
          <li>Install needed additional tools:
            <ul>
              <li>CMake from its download <a href="https://cmake.org/download/" target="_blank">page</a></li>
              <li>Cross-compiling tool. You can download it from <a href="http://gnutoolchains.com/raspberry/" target="_blank">this</a> link.</li>
            </ul>
          <li>Follow instructions of cross-compiling in the <a href="#crossCompilingLinux">Linux</a> platform from step 2, taking in account the following:
            <ol>
              <li>In steps 4.2 and 4.3, the C and C++ cross-compilers are in the bin folder where you installed the tool, normally C:\SysGCC\Raspberry\bin</li>
            </ol>
          </li>
         </ol>

<!--********************************************************************************************-->

<h1 id="whereToGoFromHere">Where to go from here?</h1>

<p>Now that you installed the required tools, it's time to start using them. Take a look at the following tutorials:</p>

<p><a href="../../html/4diacIDE/overview.html">Step 0 - 4diac IDE Overview</a></p>

<p>If you want to compile 4diac&nbsp;FORTE for another platform or want to know more about that, here's a quick link back:</p>

<p><a href="../../html/installation/install.html">Install Eclipse 4diac</a></p>

<p>If you want to go back to the Start Here page, we leave you here a fast access</p>

<p><a href="../../html/startHere/startHere.html">Where to Start</a></p>

<p class="goToTop">Or <a href="#topOfPage">Go to top</a></p>

</body>
</html>
